package com.wuyangnju.lj.callcenter.model;

import java.util.LinkedList;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.wuyangnju.lj.callcenter.model.customer.Customer;

public class Buffer {
	private static final Log log = LogFactory.getLog(Buffer.class);

	private LinkedList<Customer> customers;

	public Buffer() {
		customers = new LinkedList<Customer>();
	}

	public void admit(Customer customer) {
		customers.offer(customer);
	}

	/**
	 * @return if null, buffer is empty
	 */
	public Customer nextInQueue() {
		return customers.poll();
	}

	/**
	 * @return if false, a customer expected to be in buffer is missing
	 */
	public boolean renege(Customer customer) {
		if (customers.contains(customer)) {
			customers.remove(customer);
			return true;
		} else {
			log.error("a customer expected to be in buffer is missing!");
			return false;
		}
	}

	public int size() {
		return customers.size();
	}

}
